﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;
namespace IHISCETeim.Web.AgentSys.SvrMgr
{
    public partial class UAgentMacKeepDetailAdd : PageBase
    {
        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");
            }
        }
        protected string KeepHours
        {
            get
            {
                return GetRequestValue<string>("KeepHours", "0");
            }
        }

        protected int UMKDID
        {
            get {
                return GetRequestValue<int>("UMKDID", 0);
            }
        }

        protected string Action
        {
            get
            {
                return GetRequestValue<string>("action", "add");
            }
        }

        private UMacKeepDetailInfo _UMacKeepDetail = null;
        protected UMacKeepDetailInfo UMacKeepDetailObj
        {
            get
            {
                if (_UMacKeepDetail == null)
                    _UMacKeepDetail = UMacKeepController.UMacKeepDetail_GetByID(UMKDID);

                return _UMacKeepDetail == null ? new UMacKeepDetailInfo() { KeepHours = Convert.ToInt32(KeepHours), SerialNumber = SerialNumber, WorkTime=0, KeepDate="" } : _UMacKeepDetail;
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "UAgentMacKeepList"; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "update")
            {
                updatemenu();
            }

            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {

            UMacKeepDetailInfo item = Request.SerializableObject<UMacKeepDetailInfo>();
            item.IsVerify = 0;
            int x = UMacKeepController.UMacKeepDetail_Add(item);
            if (x == -1)
            {
                ErrorJson(string.Format("此机号{0}保养时间{1}已添加过保养，无法再次录入", item.SerialNumber, item.KeepHours));
                return;
            }
            SuccessAlertJson("保养成功");

        }

        private void updatemenu()
        {
            UMacKeepDetailInfo item = Request.SerializableObject<UMacKeepDetailInfo>();
            item.IsVerify = HasPower(IHISCETeim.Web.Permission.经销商平台_公司人员)?1:0;
            bool x = UMacKeepController.UMacKeepDetail_Update(item);
            if (!x)
            {
                ErrorJson("修改失败");
                return;
            }
            else
            {
                SuccessAlertJson("修改成功");
            }
        }


    }
}